<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ JSON.stringify(text) == '{}' ? '添加学生组织类型' : '修改学生组织类型' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules">
					<a-form-model-item label="名称" prop="Name"><a-input v-model="form.Name" /></a-form-model-item>
					<a-form-model-item label="级别" prop="Level">
						<a-radio-group name="radioGroup" v-model="form.Level">
							<a-radio :value="1">校级</a-radio>
							<a-radio :value="2">院级</a-radio>
						</a-radio-group>
					</a-form-model-item>
					<a-form-model-item label="允许加入" prop="IsJoin">
						<a-radio-group name="radioGroup" v-model="form.IsJoin">
							<a-radio :value="true">允许加入</a-radio>
							<a-radio :value="false">不允许加入</a-radio>
						</a-radio-group>
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ JSON.stringify(text) == '{}' ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
import { AddClubType, UpdateClubType } from '@/api/follow';
export default {
	props: {
		text: Object,
		departmentCVList: Array,
		chargerList: Array
	},
	watch: {
		text: function(text) {
			if (JSON.stringify(text) == '{}') {
			} else {
				this.form = text;
			}
		}
	},
	data() {
		return {
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			DepartmenDropdowntList: [],
			form: {
				Name: '',
				Level: '',
				IsJoin: ''
			},
			rules: {
				Name: [
					{
						required: true,
						message: '请输入名称',
						trigger: 'change'
					}
				],
				Level: [
					{
						required: true,
						message: '请选择级别',
						trigger: 'change'
					}
				],
				IsJoin: [
					{
						required: true,
						message: '请选择是否允许加入',
						trigger: 'change'
					}
				]
			}
		};
	},
	methods: {
		closeFunction(data) {
			this.$emit('closeFun', data);
			this.form = {};
		},
		handleSubmit(e) {
			this.$refs.ruleForm.validate(async valid => {
				if (valid) {
					let data = this.form;
					let res = {};
					if (JSON.stringify(this.text) == '{}') {
						res = await AddClubType(data);
					} else {
						res = await UpdateClubType(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				} else {
					return false;
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 100px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}

/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
</style>
